//
//  BLTopicTableViewCell.m
//  百思不得姐
//
//  Created by hbl on 16/3/21.
//  Copyright © 2016年 hbl. All rights reserved.
//

#import "BLTopicTableViewCell.h"
#import "BLTopic.h"
#import "UIImageView+WebCache.h"
#import "BLPictureView.h"
#import "BLMusicView.h"
#import "BLVideoView.h"

@interface BLTopicTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIButton *followButton;
@property (weak, nonatomic) IBOutlet UIButton *zanButton;
@property (weak, nonatomic) IBOutlet UIButton *caiButton;
@property (weak, nonatomic) IBOutlet UIButton *commentButton;
@property (weak, nonatomic) IBOutlet UIButton *repostButton;
- (IBAction)ding:(id)sender;

@property (weak, nonatomic) IBOutlet UILabel *contentTextLabel;
@property (weak, nonatomic) IBOutlet UIImageView *sinaVImagView;

@property (nonatomic, weak)BLPictureView *pictureView;
@property (nonatomic, strong)BLMusicView *musicView;
@property (nonatomic, strong)BLVideoView *videoView;
- (IBAction)followButton:(id)sender;
@end

@implementation BLTopicTableViewCell

- (BLPictureView *)pictureView
{
    if (!_pictureView) {
        BLPictureView *pictureView = [BLPictureView pictureView];
        _pictureView = pictureView;
        [self addSubview:pictureView];
    }
    return _pictureView;
}


- (BLMusicView *)musicView
{
    if (!_musicView) {
        _musicView = [BLMusicView musicView];
        [self addSubview:_musicView];
    }
    return _musicView;
}

- (BLVideoView *)videoView
{
    if (!_videoView) {
        _videoView = [BLVideoView videoView];
        [self addSubview:_videoView];
    }
    return _videoView;
}

- (IBAction)followButton:(id)sender {
  UIAlertController *actionSeet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *shouChang = [UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *juBao = [UIAlertAction actionWithTitle:@"举报" style:UIAlertActionStyleDefault handler:nil];
     UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [actionSeet addAction:shouChang];
    [actionSeet addAction:juBao];
    [actionSeet addAction:cancel];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:actionSeet animated:YES completion:nil];
}


+ (instancetype)cell
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil]lastObject];
}

- (void)awakeFromNib {
    // Initialization code
    
    UIImageView *bg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mainCellBackground"]];
    self.backgroundColor = [UIColor clearColor];
    [self setBackgroundView:bg];
    
    self.headImageView.layer.cornerRadius = 20;
    self.headImageView.clipsToBounds = YES;
}

- (void)setTopic:(BLTopic *)topic
{
    self.pictureView.hidden = YES;
    self.musicView.hidden = YES;
    self.videoView.hidden = YES;
    _topic = topic;
    self.nameLabel.text = topic.screen_name;
    self.timeLabel.text = topic.created_at;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:topic.profile_image]];
    [self.zanButton setTitle:topic.ding forState:UIControlStateNormal];
    [self.caiButton setTitle:topic.cai forState:UIControlStateNormal];
    [self.repostButton setTitle:topic.repost forState:UIControlStateNormal];
    [self.commentButton setTitle:topic.comment forState:UIControlStateNormal];
    self.contentTextLabel.text = topic.text;
    if ([self.topic.type  isEqual: @"10"] ) {
        self.pictureView.hidden = NO;
        self.pictureView.topic = topic;
        self.pictureView.frame = topic.pictureViewFrame;
    }if ([self.topic.type  isEqual: @"31"] ) {
        self.musicView.hidden = NO;
        self.musicView.topic = topic;
        self.musicView.frame = topic.pictureViewFrame;
        
    }if ([self.topic.type  isEqual: @"41"]) {
        self.videoView.hidden = NO;
        self.videoView.topic = topic;
        self.videoView.frame = topic.pictureViewFrame;
    }
        
}

- (void)setFrame:(CGRect)frame
{
//    frame = CGRectMake(5, frame.origin.y + 2, frame.size.width - 10, self.frame.size.height-3);
    frame = CGRectMake(5, frame.origin.y + 2, frame.size.width - 10, self.topic.cellHight-3);
    return [super setFrame:frame];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)ding:(id)sender {
   
}
@end
